function [connected] = checkConnectedGraph(disp_loc, matrix)

     noOfNodes = length(disp_loc); 
     secondList = zeros(1,2);       
     counter = 1;
     [firstList] = node_neighbors(1, matrix);
      numberOfNodesInFirstList = length(firstList); 
      start = 1;
      if numberOfNodesInFirstList ~= 0
                     if secondList(1,2) == 0 
                         for i = 1:numberOfNodesInFirstList
                            secondList(counter,1) = counter; 
                            secondList(counter,2) = firstList(i);
                            counter = counter + 1;
                         end
                     end                        
                         numberOfNodesInSecondList = length(secondList);
                         
                        while start ~= numberOfNodesInSecondList 
                            restartLoop = 1;
                             for i = start:numberOfNodesInSecondList
                                 if restartLoop == 1
                                    start = numberOfNodesInSecondList;
                                    restartLoop =0;
                                 end
                                 [firstList] = node_neighbors(secondList(i,2), matrix);
                                 numberOfNodesInFirstList = length(firstList);
                                 for j = 1:numberOfNodesInFirstList                                 
                                     %for k = 1:numberOfNodesInSecondList
                                         if firstList(j) ~= secondList(:,2)
                                            secondList(counter,1) = counter; 
                                            secondList(counter,2) = firstList(j);
                                            counter = counter + 1;
                                            numberOfNodesInSecondList = numberOfNodesInSecondList + 1;                                         
                                         end
                                     %end
                                 end
                             end
                        end
      end
      
      connected = 1;    
      if numberOfNodesInSecondList ~= noOfNodes 
           connected = 0; 
      end    
%     disp('The orgenal list:');
%     disp(secondList);

end